var ChoiceNum =["A、","B、","C、","D、","E、","F、","G、","H、"];
var choiceSpliter = "##";
var choiceAnswerSpliter = "##";
var selectAnswer = "";
function topic_choose_template(){
	var topic_table = $("<table id='chooseTable' class='style1'>");
	var title_tr = $("<tr id='titleTr'>");
	var title_td_tihao =$("<td id='title_td_tihao'>");
	var title_td_timu = $("<td id='title_ti_timu'>");
	var choices_tr = $("<tr><td colspan='2'><table id='choices'></table></td></tr>");
	topic_table.append(title_tr);
	title_tr.append(title_td_tihao);
	title_tr.append(title_td_timu);
	topic_table.append(choices_tr);
	return topic_table;
}

function topic_choose_choice_template(){
	var choiceLine = $("<tr><td id='choiceLineCheckBox'></td><td id='choiceLineChoiceNum'></td><td id='choiceText'></td></tr>");
	return choiceLine;
}

function topic_choose_answer_template(){
	var answer = $("<tr id='anwerTr'><td name='answer' colspan='2'></td></tr>");
	return answer;
}

function topic_choose_create(topic,page,index){
	var tableTemp = topic_choose_template();
	var table = tableTemp.clone();
	var topicNr = topic.topicNr;
	var topicDa = topic.topicDa;
//	var topicJs = topic.topicJs;
//	var topicKm =topic. topicKm;
//	var topicLb = topic.topicLb;
	var topicTm = topic.topicTm;
	var topicTx = topic.topicTx;
//	var topicZj = topic.topciZj;
	var topicId = topic.topicId;
	$(table).attr("id",topicId);
	var tempSpan = $("<span>");
	tempSpan.html(topic_cult_topicNum(page,index));
	$(table).find("#title_td_tihao").append(tempSpan);
	tempSpan =  $("<span>");
	tempSpan.html(topicTm);
	$(table).find("#title_ti_timu").append(tempSpan);
	var choiceTable = $(table).find("#choices");
	var nr = topicNr.split(choiceSpliter);
	$(nr).each(function(i,n){
		var nrTable = topic_choose_choice_template();
		var checkBox = $("<input name='check_"+topicId+"' type='"+(topicTx=="checkbox"?"checkbox":"radio")+"' value='"+i+"'>");
		nrTable.find("#choiceLineCheckBox").append(checkBox);
		nrTable.find("#choiceLineChoiceNum").html(ChoiceNum[i]);
		nrTable.find("#choiceText").html(n);
		topic_regEvent(topic,checkBox,topicDa);
		choiceTable.append(nrTable);
	});	
	var topicTr = $("<tr>");
	var topicTd = $("<td>");
	var answerTr = topic_choose_answer_template();
	answerTr.attr("id","answer_"+topicId);
	table.append(answerTr);
	topicTd.append(table);
	topicTr.append(topicTd);
	$("#topic").append(topicTr);
}

function topic_regEvent(topic,checkbox){
	if(topic.topicTx=="checkbox"){
		return;
	}else if(topic.topicTx=="radio"){
		checkbox.bind("click",function(){
			topic_check_single_select_answer(topic,$(this));
		});
	}
}

function topic_check_single_select_answer(topic,check){
	var checkValue = check.val();
	var correctAnswer = topic.topicDa;
	var correctAnswerIndex = "";
	var topicNr = topic.topicNr.split(choiceSpliter);
	$(correctAnswer.split(choiceAnswerSpliter)).each(function(i,n){
		if(n=="1"){
			correctAnswerIndex=i;
			return false;
		}
	});
	selectAnswer = checkValue+"_" + topic.topicId;
	alert(selectAnswer);
//	$("#answer_"+topic.topicId).find("td[name='answer']").html("您的答案："+ChoiceNum[checkValue]+topicNr[checkValue]+" "
//			+(correctAnswerIndex==checkValue?"<font color='blue'>正确</font>":"<font color='red'>错误</font><br />正确答案是："+ChoiceNum[correctAnswerIndex]+topicNr[correctAnswerIndex]));
}

function topic_cult_topicNum(page,index){
	return page.currentPage+(page.currentPage-1)*(page.rowPerPage-1)+index;
}